/**
 * 
 */
package fr.isima.gui;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import fr.isima.R;
import fr.isima.tools.LocationRecorderService;

/**
 * @author vincent
 */
public class TrackRecord extends Activity
{

    private static final String TAG  = "TrackRecord";

    public static final String  STOP = "fr.isima.gui.STOP";

    private Button              buttonStop;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.track_record);

        startService(new Intent(this, LocationRecorderService.class));

        buttonStop = (Button) findViewById(R.id.buttonStop);

        buttonStop.setOnClickListener(new OnClickListener()
        {

            public void onClick(View v)
            {
                SharedPreferences preferences = getSharedPreferences(
                        TrackPreferences.USER_PREFERENCE, Activity.MODE_PRIVATE);

                Intent stopRecording = new Intent(STOP);
                Log.d(TAG, "Sending broadcast " + STOP);
                stopRecording.putExtra(TrackPreferences.PREF_TRACK_NAME,
                        preferences.getString(TrackPreferences.PREF_TRACK_NAME,
                                "default"));
                sendBroadcast(stopRecording);
                Intent stopService = new Intent(v.getContext(),
                        LocationRecorderService.class);
                stopService(stopService);
                Intent end = new Intent(v.getContext(), TrackSaving.class);
                startActivity(end);
            }
        });
    }

}
